package com.news.service;

import com.news.dao.NewsDao;
import com.news.dao.NewsDaoImpl;
import com.news.entity.News;
import com.news.util.Page;

public class NewsServiceImpl implements NewsService {

    private NewsDao newsDao = new NewsDaoImpl();

    @Override
    public int saveNews(News news) {
        return newsDao.insertNews(news);
    }

    @Override
    public int editNews(News news) {
        return newsDao.updateNews(news);
    }

    @Override
    public int removeNews(int id) {
        return newsDao.deleteNews(id);
    }

    @Override
    public int removeNewsBatch(String[] ids) {
//		return userDao.deleteUserBatch(ids);
        return newsDao.deleteNewsBatch2(ids);
    }

    @Override
    public News getNews(int id) {
        return newsDao.selectOneNews(id);
    }

    @Override
    public Page listNews(int pageNum, int pageSize, String name) {
        //创建分页组件对象
        Page page = new Page();
        //设置当前页数
        page.setPageNum(pageNum);
        //设置每页条数
        if(pageSize!=0){
            page.setPageSize(pageSize);
        }
        //设置总记录数
        page.setTotal(newsDao.selectCount(name));
        //设置当前页数据
        page.setData(newsDao.selectNews(page.getOffset(), page.getPageSize(), name));
        return page;
    }


}
